/**
 * 桌面的牌
 */
class Table extends eui.Component {
	public tag: string = "";
	public constructor() {
		super();
	}

	public childrenCreated(): void {

	}
	private index = 0;
	public setCard(value: number): void {
		if (this.index > 20) {
			this.index = 20
		}
		var card = (this.getChildByName(this.index.toString()) as TabelCard);
		card.visible = true;
		card.setData(value);
		this.index++;
	}

	public loseCard(): void {
		this.index = this.index - 1 >= 0 ? this.index - 1 : 0;
		if (this.index >= 0) {
			var card = (this.getChildByName(this.index.toString()) as TabelCard);
			card.visible = false;
		}
	}

	public hideLight(): void {
		if (this.index != 0) {
			(this.getChildByName((this.index - 1).toString()) as TabelCard).hideLight();
		}
	}

	public clear(): void {
		for (let i = 0; i < 21; i++) {
			var item = this.getChildByName(i.toString()) as TabelCard;
			item.visible = false;
			item.hideLight();
		}
		this.index = 0;
	}
}